package com.cmbc.xiaodu;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/minshengAction")
public class MinShengAction extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 根据request创建Bot
        MinShengBot bot;
        try {
            bot = new MinShengBot(request);
            // 线下调试时，可以关闭签名验证
            // bot.enableVerify();
            bot.disableVerify();
            // 调用bot的run方法
            String responseJson = bot.run();
            // 设置response的编码UTF-8
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/json; charset=utf-8");
            // 返回response
            response.getWriter().append(responseJson);

            // 打开签名验证
            // bot.enableVerify();

        } catch (Exception e) {
            e.printStackTrace();
            response.getWriter().append(e.toString());
        }
    }




    /**
     * @see HttpServlet#HttpServlet()
     */
    public MinShengAction() {
        super();
    }

    /**
     * @see HttpServlet#doHead(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doHead(HttpServletRequest requestm, HttpServletResponse response) {
        response.setStatus(204);
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest requestm, HttpServletResponse response) {
        response.setStatus(204);
    }
}
